/**
 * 
 */
package com.worksmap.core.service.impl;

import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Service;

import com.worksmap.core.constant.RateConstant;
import com.worksmap.core.entity.TaoBaoSeller;
import com.worksmap.core.service.CookieService;
import com.worksmap.core.util.CookieUtil;
import com.worksmap.core.util.encrypt.MD5;

/**
 * @author shhc
 *
 */
@Service
public class CookieServiceImpl implements CookieService {

	@Override
	public void setCookie(TaoBaoSeller seller, HttpServletResponse response)
			throws Exception {
		//授权
		String sessionId = getSessionIdForSeller(seller);
		CookieUtil.setPageCookie(response, RateConstant.SESSION_ID_NAME, sessionId, 
				RateConstant.WORKSMAP_CENTER_DOMAIN);
		CookieUtil.setPageCookie(response, RateConstant.SELLER_SESSION_ID_NAME, 
				String.valueOf(seller.getTaobao_user_id()), RateConstant.WORKSMAP_CENTER_DOMAIN);
	}

	@Override
	public String getSessionIdForSeller(TaoBaoSeller seller) {
		return MD5.encodePassword(seller.getTaobao_user_id() + "-" +
				RateConstant.SELLER_SESSION_ID_KEY + "-" + seller.getTaobao_user_nick(), "MD5");
	}

}
